findFocusImgList();//首页轮播图加载函数
findRestaurantByRcId();//根据餐厅分类查询餐厅列表

//首页轮播图加载函数
function findFocusImgList(){
	var page = 0;
	var size = 5;
	
	var sort = new Array();
	sort.push("id");
	
	var obj = JSON.stringify({
		
	});
    httpHelperpost(_API_FIND_FOCUS_IMG_LIST+"?page="+page+"&size="+size+"&sort="+sort, obj, function(isSuccess, data) {
        if (isSuccess == true) {
            var response = data.responseText;
            var value = JSON.parse(response);
    			
   			// console.log(response);
   			var shuffHtml = "";
   			
   			for(var i=0;i<value.data.content.length;i++){
   				shuffHtml+="<div class='swiper-slide'><img src="+value.data.content[i].image+"></div>";
   			}
   			
   			$(".swiper-wrapper").html(shuffHtml);

            if(value.code == 0){
             	console.log("查询成功");
             	//初始化轮播图插件
             	var mySwiper = new Swiper ('.swiper-container', {
				    	direction: 'horizontal',
				    	loop: true,
				    
				    	// 如果需要分页器
				    	pagination: '.swiper-pagination',
				    	paginationClickable: true,
				});
            }else if(value.code==401){
              alert(value.message);
              window.location.href='./index.html';
            }else{
             	console.log("查询失败");
              alert(value.message);
            }
        }else {}
    });
}
//根据餐厅分类查询餐厅列表
function findRestaurantByRcId(isRefresh){
	var page = Math.ceil($(".everyDay .everyDay-li").length/size);
	var size = 30;
	
	var sort = new Array();
	sort.push("id");
	
	var Request = new Object();
	Request = GetRequest();
	var rcId = Request['rcId'];

	var obj = JSON.stringify({
		"rcId": rcId
	});
    httpHelperpost(_API_FIND_RESTAURANT_BY_RCID+"?page="+page+"&size="+size+"&sort="+sort, obj, function(isSuccess, data) {
        if (isSuccess == true) {
            var response = data.responseText;
            var value = JSON.parse(response);
    			
   			console.log(response);
   			
            if(value.code == 0){
             	console.log("查询成功");
                var rcHtml = "";

                var activity = new Array();
                var activityHtml = "";
                var supportHtml = "";
                for(var i=0;i<value.data.length;i++){
                    if(value.data[i].fullReduceActivity==null||value.data[i].fullReduceActivity==""||value.data[i].fullReduceActivity==undefined){
                        activityHtml = "";
                    }else{
                        activityHtml = "<img src='./img/pre_01.png'><span class='prefer-inc'>";
                        activity = value.data[i].fullReduceActivity.split(",");
                        
                        for(var j=0;j<activity.length-1;j++){
                            activityHtml += "<span>"+activity[j]+"</span>";
                        }
                        activityHtml+="</span>";
                    }

                    if(value.data[i].dispatchType==null||value.data[i].dispatchType==""||value.data[i].dispatchType==undefined){
    
                    }else{
                        supportHtml = "<div class='everyDay-support'>";
                        for(var k=0,len = value.data[i].dispatchType.split(":").length;k<len;k++){
                            if(value.data[i].dispatchType.split(":")[k]==1){
                                supportHtml+="支持食堂&nbsp&nbsp";
                            }else if(value.data[i].dispatchType.split(":")[k]==2){
                                supportHtml+="支持外卖&nbsp&nbsp";
                            }else if(value.data[i].dispatchType.split(":")[k]==3){
                                supportHtml+="支持自取&nbsp&nbsp";
                            }
                        }
                    }

                    rcHtml += "<li class='everyDay-li' onclick=window.location.href='./detail.html?id="+value.data[i].id+"'>"
                        +"<div class='everyDay-img'><img src="+value.data[i].icon+"></div>"
                        +"<div class='everyDay-bar'>"
                        +"<div>"
                        +"<span class='everyDay-title'>"+textisNull(value.data[i].name)+"</span>"
                        // +"<img class='everyDay-more' src='./img/dot_01.png'>"
                        +"</div>"
                        +"<div class='everyDay-star'>";
                            for(var j=0,len=Math.round(levelisNull(value.data[i].evaluationLevel));j<len;j++){
                                liHtml+="<img src='./img/start.png'>";
                            }
                    rcHtml+="</div>"
                        +"<div class='everyDay-detail'>"
                        +"<div>起送￥<span>"+value.data[i].limitPrice+"</span></div>"
                        +"<div>配送费<span class='shipFee'>"+value.data[i].dispatchPrice+"</span>元</div>"
                        //+"<div><span class='everyDay-min'>53分钟</span><span class='everyDay-shu'>|</span><span>1.6km</span></div>"
                        +"</div>"
                        +"<div></div>"
                            +supportHtml
                        // +"<div class='everyDay-support'>支持自取</div>"
                        +"<div class='everyDay-prefer'>"
                            +activityHtml
                        // +"<img src='./img/pre_01.png'>"
                        // +"<span class='prefer-inc'>"+"</span>"
                        +"</div></div></li>";
                }
                if(isRefresh==0){
                    $(".everyDay ul").html(rcHtml);
                }else{
                    $(".everyDay ul").append(rcHtml);
                }
                
                             	
            }else if(value.code==401){
              alert(value.message);
              window.location.href='./index.html';
            }else{
             	console.log("查询失败");
              alert(value.message);
            }
        }else {}
    });

    function levelisNull(value){
        if(value==null||value==undefined){
            value = 0;
        }
        return value;
    }
    function textisNull(value){
        if(value==null||value==undefined){
            value = "";
        }
        return value;
    }
}

//下拉刷新
function dropRefresh(){
    $(window).scroll(function() {
        var scrollTop = $(document).scrollTop();//滚动条距离页面顶部距离
        var offsetHeight = $(document).height();//当前页面高度(包括滚动页面)
        var clientHeight = $(this).height();//当前页面高度(不包括滚动页面)
        var bottomHeight = scrollTop-(offsetHeight-clientHeight);
        
        if(bottomHeight<2&&bottomHeight>-2){
            // console.log(bottomHeight);
            findRestaurantByRcId(1);
            $(window).unbind("scroll");     
        }
    });
}

//获取url中"?"符后的字串
function GetRequest() {
    var url = location.search; //获取url中"?"符后的字串   
    
    var theRequest = new Object();
    if (url.indexOf("?") != -1) {
      var str = url.substr(1);
      
      strs = str.split("&");
      
      for (var i = 0; i < strs.length; i++) {
        
        theRequest[strs[i].split("=")[0]] = strs[i]
            .split("=")[1];
      }
    }
    return theRequest;
}

